//required vue-router
const CustomRouter = {
  install:function (Vue, options) {
    // 4. 添加实例方法
    Vue.prototype.$nocacheRouter = function (url,query) {
      var names = url.split('?')[0];
      let name = names.substr(1);
      let cachPagesStr = this.$store.state.cachPages;
      let cachPagesArry = cachPagesStr.split(',');
      let findIndex = cachPagesArry.findIndex(elm=>elm == name);
      if(findIndex != -1) {
        cachPagesArry.splice(findIndex,1);
      }
      //数组去重
      cachPagesArry = Array.from(new Set(cachPagesArry));
      this.$store.state.cachPages = cachPagesArry.join(',');
      this.$nextTick(function(){
        //相同url刷新路由
        if(url && url.indexOf(this.$route.path) != -1) {
          this.$store.state.reloadUrl = false;
          this.$nextTick(function () {
            this.$store.state.reloadUrl = true;
            this.$router.push({path:url,query:query});
          });
        }else {
          this.$router.push({path:url,query:query});
        }
      });
    }
  }
};
export default CustomRouter;
